[svn] / public / sloppy / test.lsl Repository:
ViewVC logotype

View of /public/sloppy/test.lsl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 39 - (download) (annotate)
Sun Aug 31 19:51:38 2008 UTC (32 hours, 2 minutes ago) by anari
File size: 5429 byte(s)
Move sloppy to public.
// Copyright (c) 2008, Anari Demme
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
//   this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
//   notice, this list of conditions and the following disclaimer in the
//   documentation and/or other materials provided with the distribution.
// * Neither the names of any contributors nor the names of any organizations
//   affiliated with the contributors may be used to endorse or promote
//   products derived from this software without specific prior written
//   permissions.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

// $Id$

// Configuration variables.

// NOTE: This server is only for use for this demonstration.  Do not use this
//       server for any production purposes.  I reserve the right to sabotage
//       your data in entertaining ways if you do. :)
string site = "http://sloppydemo.appspot.com/";
key http_key;

// Tests, one per row.
// 1: type of request, 2: relative url, 3: expected return code, 4: expected
// data (if appliccable)

list tests = [
  "GET",      "nonono",   404,    "",
  "DELETE",   "nonono",   404,    "",
  
  "PUT",      "",         403,    "",
  "GET",      "",         403,    "",
  "DELETE",   "",         403,    "",
      
  "GET",      "new",      404,    "",
  "PUT",      "new",      201,    "some data",
  "GET",      "new",      200,    "some data",
  "DELETE",   "new",      200,    "",
  "GET",      "new",      404,    "",
  
  "GET",      "deepdir",                  404, "",
  "GET",      "deepdir/2/3/4/5/6/7/8",    404, "",
  "GET",      "deepdir/2",                404, "",
  "PUT",      "deepdir/2/3/4/5/6/7/8",    201, "a thing",
  "GET",      "deepdir/2/3/4/5/6/7/8",    200, "a thing",
  "GET",      "deepdir/2/3/4",            404, "",
  "PUT",      "deepdir/2/3/4/5/6/7/9",    201, "another thing",
  "DELETE",   "deepdir/2/3/4/5/6/7/8",    200, "",
  "GET",      "deepdir/2/3/4/5/6/7/9",    200, "another thing",
  "DELETE",   "deepdir",                  404, "",
  "DELETE",   "deepdir/",                 200, "",
  "GET",      "deepdir/2/3/4/5/6/7/9",    404, ""
  
  // add directory listing tests
  // add directory delete vs record delete
  // add delete record wh ile leaving directory tree intact
  
];
  
integer current_test = 0;
integer failures = 0;
integer warnings = 0;

// This has no throttling so will easily hit the llHTTPRequest resouce
// limitations if more tests are added, or its ran twice in succession.
run_test() {
    if (llGetListLength(tests) == current_test * 4) {
        llWhisper(0, "Completed all tests.  " + (string) warnings + " warnings; " + (string) failures + " failures.");
        return;
    }
    
    list test   = llList2List(tests, current_test * 4, (current_test * 4) + 4);
    string req  = llList2String(test, 0);
    string name = llList2String(test, 1);
    integer ret = llList2Integer(test, 2);
    string data = llList2String(test, 3);
    
    llWhisper(0, "Running test " + (string) current_test + ": " + req + " " + name + " " + (string) ret + " " + "\"" + data + "\"");
    http_key = llHTTPRequest(site + name, [ HTTP_METHOD, req ], data);
}  

default {
    state_entry() {
        llWhisper(0, "Running " + (string) (llGetListLength(tests) / 4) + " tests.\n");
        current_test = 0;
        failures = 0;
        warnings = 0;
        run_test();
    }
        

    http_response(key req, integer status, list meta, string content) {
        if (req != http_key) {
            llWhisper(0, "Unexpected HTTP response.");
            ++warnings;
            return;
        }
        list test   = llList2List(tests, current_test * 4, (current_test * 4) + 4);
        string req  = llList2String(test, 0);
        string name = llList2String(test, 1);
        integer ret = llList2Integer(test, 2);
        string data = llList2String(test, 3);
        
        if (status != ret) {
            llWhisper(0, "Fail test " + (string) current_test + ": Expected status " + (string) ret + " but got " + (string) status);
            ++failures;
        } else if (req == "GET" && ret == 200 && content != data) {
            llWhisper(0, "Fail test " + (string) current_test + ": Expected return '" + data + "' but got '" + content + "'");
            ++failures;
        } else {
            llWhisper(0, "Pass test " + (string) current_test);
        }
        
        ++current_test;
        run_test();
    }
}

Anari Demme
ViewVC Help
Powered by ViewVC 1.0.5